import React from 'react'
import {connect} from 'react-redux'
import PropTypes from 'prop-types'

import TodoTextInput from '../components/TodoTextInput'
import {addTodo} from '../actions'

export const Header = ({addTodo}) => (
    <header>
        <h1>待办事项</h1>
        <TodoTextInput
        newTodo
        onSave={(text) => {
            if(text.length !== 0){
                addTodo(text)
            }
        }}
        placeholder="请录入待办事项"
        />
    </header>
)
Header.propTypes = {
    addTodo: PropTypes.func.isRequired
}

export default connect(null, { addTodo })(Header)